package com.rrqs.activity.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zadtek.xmqishi.R;
import com.rrqs.activity.data.OrderdetailFood;

/**
 * 商品列表
 * @author Administrator
 *
 */
public class ShopdetAdapter extends BaseAdapter {

	private Context context;
	/**
	 * 显示数据的集合
	 */
	ArrayList<OrderdetailFood> cdlistdata;
	Intent intent;

	public ShopdetAdapter(Context context, ArrayList list) {
		this.context = context;
		this.cdlistdata = list;
	}

	@Override
	public int getCount() {
		return cdlistdata != null ? cdlistdata.size() : 0;
	}

	@Override
	public Object getItem(int position) {
		return cdlistdata.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (cdlistdata != null) {
			ViewHolder holder = null;
			if (convertView == null) {
				convertView = LayoutInflater.from(context).inflate(
						R.layout.orderlist_item, null);
				holder = new ViewHolder();

				holder.foodname = (TextView) convertView
						.findViewById(R.id.foodname);
				holder.foodnum = (TextView) convertView
						.findViewById(R.id.foodnum);
				holder.foodprice = (TextView) convertView
						.findViewById(R.id.foodprice);
				convertView.setTag(holder);

			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			if (convertView != null) {
				if (cdlistdata.size() > position) {
					holder.foodname.setText(cdlistdata.get(position).getFname());
					holder.foodnum.setText("x" + cdlistdata.get(position).getQuantity());
					holder.foodprice.setText("¥" + cdlistdata.get(position).getPrice());
				}
			}
		}
		return convertView;
	}

	public static class ViewHolder {
		TextView foodname;
		TextView foodnum;
		TextView foodprice;
	}
}
